#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_solvesr.info <<'%EOF%'
   rsp_solvesr
   -----------
   Molecule:         CH3 radical
   Wave Function:    MCSCF (CAS)
   Test Purpose:     ESR hyperfine couplings with solvent effects
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_solvesr.mol <<'%EOF%'
INTGRL
Calculation of ESR hyperfine couplings with solvent for the CH3 radical

    2    1  Y         1.00D-15
        6.    1    4    3    1    1    1
 C    0.00000    0.00000   0.0000
    2    0
74124.
24708.
    7    0
8236.000
1235.000
280.8000
79.27000
25.59000
8.997000
3.319000
    3    0
.9059000
.3643000
.1285000
    5    3
18.71000  .01403100 .00000000 .00000000
4.133000  .08686600 .00000000 .00000000
1.200000  .29021600 .00000000 .00000000
.3827000  .50100800 1.0000000 .00000000
.1209000  .34340600 .00000000 1.0000000
    2    2
1.0970000 1.0000000 .00000000
.31800000 .00000000 1.0000000
    1    1
.76100000 1.00000000
        1.    2    3    2    1    1
 H1   -.118598   0.00000  2.036247
 H2   -.118598  1.763441 -1.018124
    2    0
304.83
101.61
    5    0
33.87000
5.095000
1.159000
0.325800
0.102700
    2    0
1.407000
.3880000
    1    1
1.057000  1.00000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_solvesr.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONSE
**INTEGRALS
.FC
.SD
*ONEINT
.SOLVENT
 12
**WAVE FUNCTIONS
.HF
.MCSCF
*SCF INPUT
.DOUBLY OCCUPIED
 3 1
.OPEN SH
 1
*CONFIGURATION INPUT
.INACTIVE
 1 0
.CAS SPACE
 5 2
.ELECTRONS
 7
.SPIN MULTIPLICITY
 2
.SYMMETRY
 1
*SOLVENT
.CAVITY
 4.119
.DIELEC
 1.70
.MAX L
 12
*OPTIMIZATION
.DETERMINANTS
.THRESHOLD
 1D-8
.TRACI
**RESPON
.TRPFLG
*ESR
.TRPPRP
FC  C001
.TRPPRP
FC  H002
.TRPPRP
FC  H003
.TRPPRP
FC  H004
.TRPPRP
SD 001 x
.TRPPRP
SD 001 y
.TRPPRP
SD 001 z
.TRPPRP
SD 002 x
.TRPPRP
SD 002 y
.TRPPRP
SD 002 z
.TRPPRP
SD 003 x
.TRPPRP
SD 003 y
.TRPPRP
SD 003 z
.TRPPRP
SD 004 x
.TRPPRP
SD 004 y
.TRPPRP
SD 004 z
.TRPPRP
SD 005 x
.TRPPRP
SD 005 y
.TRPPRP
SD 005 z
.TRPPRP
SD 006 x
.TRPPRP
SD 006 y
.TRPPRP
SD 006 z
.TRPPRP
SD 007 x
.TRPPRP
SD 007 y
.TRPPRP
SD 007 z
.TRPPRP
SD 008 x
.TRPPRP
SD 008 y
.TRPPRP
SD 008 z
.TRPPRP
SD 009 x
.TRPPRP
SD 009 y
.TRPPRP
SD 009 z
.TRPPRP
SD 010 x
.TRPPRP
SD 010 y
.TRPPRP
SD 010 z
.TRPPRP
SD 011 x
.TRPPRP
SD 011 y
.TRPPRP
SD 011 z
.TRPPRP
SD 012 x
.TRPPRP
SD 012 y
.TRPPRP
SD 012 z
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_solvesr.check
cat >>rsp_solvesr.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# Integral setup
CRIT1=`$GREP "Calculation of one\- and two\-electron Hamiltonian integrals\." $log | wc -l`
CRIT1b=`$GREP "Calculation of one\-electron Hamiltonian integrals\." $log | wc -l`
CRIT2=`$GREP "The following one\-electron property integrals are calculated" $log | wc -l`
CRIT3=`$GREP "\- overlap integrals" $log | wc -l`
CRIT4=`$GREP "\- Fermi contact integrals" $log | wc -l`
CRIT5=`$GREP "\(Dirac delta function integrals\)" $log | wc -l`
CRIT6=`$GREP "\- spin\-dipole integrals" $log | wc -l`
CRIT7=`$GREP "\(electron spin \- nuclear moment coupling\)" $log | wc -l`
CRIT8=`$GREP "two-electron integrals are transformed to P-supermatrix elements" $log | wc -l`
CRIT8b=`$GREP "Fock matrices are calculated directly and in parallel without use of integrals on disk" $log |wc -l`
CRIT9=`$GREP "Integrals for all indirect spin\-spin coupling and/or shielding tensors are calculated\." $log | wc -l`
CRIT10=`$GREP "One\-electron RLM integrals calculated\." $log | wc -l`
CRIT11=`$GREP "Maximum L quantum number\: 12" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT1b \+ $CRIT8b`
CTRL[1]=11
ERROR[1]="INTEGRAL CALCULATION NOT SET UP CORRECTLY"

# Basis set
CRIT1=`$GREP "C * 1 * 6\.0000 * 44 * 38 * \[12s5p2d1f\|12s3p2d1f\]" $log | wc -l`
CRIT2=`$GREP "H * 3 * 1\.0000 * 18 * 18 * \[7s2p1d\|7s2p1d\]" $log | wc -l`
CRIT4=`$GREP "total\: * 4 * 9\.0000 * 98 * 92" $log | wc -l`
CRIT5=`$GREP "Spherical harmonic basis used\." $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT4 \+ $CRIT5`
CTRL[2]=4
ERROR[2]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 12" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT4=`$GREP "3 * z * (0| )\.0000000000" $log | wc -l`
CRIT5=`$GREP "4 * x * (\-0|\-)\.1185980000" $log | wc -l`
CRIT6=`$GREP "5 * y * (0| )\.0000000000" $log | wc -l`
CRIT7=`$GREP "6 * z * 2\.0362470000" $log | wc -l`
CRIT8=`$GREP "7 * x * (\-0|\-)\.1185980000" $log | wc -l`
CRIT9=`$GREP "8 * y * 1\.7634410000" $log | wc -l`
CRIT10=`$GREP "9 * z * \-1\.0181240000" $log | wc -l`
CRIT11=`$GREP "10 * x * (\-0|\-)\.1185980000" $log | wc -l`
CRIT12=`$GREP "11 * y * \-1\.7634410000" $log | wc -l`
CRIT13=`$GREP "12 * z * \-1\.0181240000" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13`
CTRL[3]=13
ERROR[3]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 7 * 5" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 60 * 32" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="SYMMETRY NOT CORRECT"

# Energy
CRIT1=`$GREP "Final MCSCF energy\: * \-39\.6333670869[56]" $log | wc -l`
TEST[5]=`expr	$CRIT1`
CTRL[5]=1
ERROR[5]="MCSCF ENERGY NOT CORRECT"

# ESR setup
CRIT1=`$GREP "22 ESR CALC\. \: TRIPLET OP\. * SYMMETRY NO\: * 1 AND LABEL\:" $log | wc -l`
CRIT2=`$GREP "18 ESR CALC\. \: TRIPLET OP\. * SYMMETRY NO\: * 2 AND LABEL\:" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2`
CTRL[6]=2
ERROR[6]="ESR CALCULATION NOT SET UP CORRECTLY"

# ESR parameters
CRIT1=`$GREP "TRIPLET OPERATOR\: \"FC  C001\" LAGRANGIAN\: \-1\.51631[0-9] AVERAGE\: * 2\.36947[0-9] TOTAL\: * (0| )\.85315[0-9]" $log | wc -l`
CRIT2=`$GREP "TRIPLET OPERATOR\: \"FC  H002\" LAGRANGIAN\: (\-0| \-)\.02257[0-9] AVERAGE\: (\-0| \-)\.15185[0-9] TOTAL\: (\-0| \-)\.17443[0-9]" $log | wc -l`
CRIT3=`$GREP "TRIPLET OPERATOR\: \"FC  H003\" LAGRANGIAN\: (\-0| \-)\.04515[0-9] AVERAGE\: (\-0| \-)\.30371[0-9] TOTAL\: (\-0| \-)\.34887[0-9]" $log | wc -l`
CRIT4=`$GREP "TRIPLET OPERATOR\: \"SD * 001 y\" LAGRANGIAN\: (\-0| \-)\.02074[0-9] AVERAGE\: (\-0| \-)\.52459[0-9] TOTAL\: (\-0| \-)\.54534[0-9]" $log | wc -l`
CRIT5=`$GREP "TRIPLET OPERATOR\: \"SD * 002 y\" LAGRANGIAN\: * (0| )\.00168[0-9] AVERAGE\: (\-0| \-)\.08072[0-9] TOTAL\: (\-0| \-)\.07904[0-9]" $log | wc -l`
CRIT6=`$GREP "TRIPLET OPERATOR\: \"SD * 003 y\" LAGRANGIAN\: * (0| )\.00432[0-9] AVERAGE\: (\-0| \-)\.01322[0-9] TOTAL\: (\-0| \-)\.00889[0-9]" $log | wc -l`
CRIT7=`$GREP "TRIPLET OPERATOR\: \"SD * 004 y\" LAGRANGIAN\: (\-0| \-)\.02501[0-9] AVERAGE\: * (0| )\.09585[0-9] TOTAL\: * (0| )\.07083[0-9]" $log | wc -l`
CRIT8=`$GREP "TRIPLET OPERATOR\: \"SD * 005 y\" LAGRANGIAN\: * (0| )\.01638[0-9] AVERAGE\: (\-0| \-)\.14855[0-9] TOTAL\: (\-0| \-)\.13216[0-9]" $log | wc -l`
CRIT9=`$GREP "TRIPLET OPERATOR\: \"SD * 006 x\" LAGRANGIAN\: * (0| )\.04149[0-9] AVERAGE\: * 1\.04919[0-9] TOTAL\: * 1\.09068[0-9]" $log | wc -l`
CRIT10=`$GREP "TRIPLET OPERATOR\: \"SD * 006 z\" LAGRANGIAN\: * (\-0|\-|0| )\.000000 AVERAGE\: * (\-0|\-|0| )\.000000 TOTAL\: * (\-0|\-|0| )\.000000" $log | wc -l`
CRIT11=`$GREP "TRIPLET OPERATOR\: \"SD * 007 x\" LAGRANGIAN\: * (\-0|\-|0| )\.000000 AVERAGE\: * (\-0|\-|0| )\.000000 TOTAL\: * (\-0|\-|0| )\.000000" $log | wc -l`
CRIT12=`$GREP "TRIPLET OPERATOR\: \"SD * 007 z\" LAGRANGIAN\: (\-0| \-)\.02074[0-9] AVERAGE\: (\-0| \-)\.52459[0-9] TOTAL\: (\-0| \-)\.54534[0-9]" $log | wc -l`
CRIT13=`$GREP "TRIPLET OPERATOR\: \"SD * 008 x\" LAGRANGIAN\: * (0| )\.01555[0-9] AVERAGE\: (\-0| \-)\.01008[0-9] TOTAL\: * (0| )\.00547[0-9]" $log | wc -l`
CRIT14=`$GREP "TRIPLET OPERATOR\: \"SD * 008 z\" LAGRANGIAN\: * (0| )\.00250[0-9] AVERAGE\: (\-0| \-)\.00763[0-9] TOTAL\: (\-0| \-)\.00513[0-9]" $log | wc -l`
CRIT15=`$GREP "TRIPLET OPERATOR\: \"SD * 009 x\" LAGRANGIAN\: * (0| )\.00250[0-9] AVERAGE\: (\-0| \-)\.00763[0-9] TOTAL\: (\-0| \-)\.00513[0-9]" $log | wc -l`
CRIT16=`$GREP "TRIPLET OPERATOR\: \"SD * 009 z\" LAGRANGIAN\: (\-0| \-)\.01724[0-9] AVERAGE\: * (0| )\.09080[0-9] TOTAL\: * (0| )\.07356[0-9]" $log | wc -l`
CRIT17=`$GREP "TRIPLET OPERATOR\: \"SD * 010 x\" LAGRANGIAN\: * (0| )\.03111[0-9] AVERAGE\: (\-0| \-)\.02016[0-9] TOTAL\: * (0| )\.01094[0-9]" $log | wc -l`
CRIT18=`$GREP "TRIPLET OPERATOR\: \"SD * 010 z\" LAGRANGIAN\: (\-0| \-)\.00250[0-9] AVERAGE\: * (0| )\.00763[0-9] TOTAL\: * (0| )\.00513[0-9]" $log | wc -l`
CRIT19=`$GREP "TRIPLET OPERATOR\: \"SD * 011 x\" LAGRANGIAN\: * (0| )\.00432[0-9] AVERAGE\: (\-0| \-)\.01322[0-9] TOTAL\: (\-0| \-)\.00889[0-9]" $log | wc -l`
CRIT20=`$GREP "TRIPLET OPERATOR\: \"SD * 011 z\" LAGRANGIAN\: * (0| )\.01638[0-9] AVERAGE\: (\-0| \-)\.14855[0-9] TOTAL\: (\-0| \-)\.13216[0-9]" $log | wc -l`
CRIT21=`$GREP "TRIPLET OPERATOR\: \"SD * 012 x\" LAGRANGIAN\: (\-0| \-)\.00250[0-9] AVERAGE\: * (0| )\.00763[0-9] TOTAL\: * (0| )\.00513[0-9]" $log | wc -l`
CRIT22=`$GREP "TRIPLET OPERATOR\: \"SD * 012 z\" LAGRANGIAN\: (\-0| \-)\.00609[0-9] AVERAGE\: (\-0| \-)\.07568[0-9] TOTAL\: (\-0| \-)\.08178[0-9]" $log | wc -l`
CRIT23=`$GREP "TRIPLET OPERATOR\: \"FC  H004\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT24=`$GREP "TRIPLET OPERATOR\: \"SD * 001 x\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT25=`$GREP "TRIPLET OPERATOR\: \"SD * 001 z\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT26=`$GREP "TRIPLET OPERATOR\: \"SD * 002 x\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT27=`$GREP "TRIPLET OPERATOR\: \"SD * 002 z\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT28=`$GREP "TRIPLET OPERATOR\: \"SD * 003 x\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT29=`$GREP "TRIPLET OPERATOR\: \"SD * 003 z\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT30=`$GREP "TRIPLET OPERATOR\: \"SD * 004 x\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT31=`$GREP "TRIPLET OPERATOR\: \"SD * 004 z\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT32=`$GREP "TRIPLET OPERATOR\: \"SD * 005 x\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT33=`$GREP "TRIPLET OPERATOR\: \"SD * 005 z\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT34=`$GREP "TRIPLET OPERATOR\: \"SD * 006 y\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT35=`$GREP "TRIPLET OPERATOR\: \"SD * 007 y\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT36=`$GREP "TRIPLET OPERATOR\: \"SD * 008 y\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT37=`$GREP "TRIPLET OPERATOR\: \"SD * 009 y\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT38=`$GREP "TRIPLET OPERATOR\: \"SD * 010 y\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT39=`$GREP "TRIPLET OPERATOR\: \"SD * 011 y\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
CRIT40=`$GREP "TRIPLET OPERATOR\: \"SD * 012 y\" contribution \= (0| )\.0 by symmetry" $log | wc -l`
TEST[7]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14 \+ $CRIT15 \+ $CRIT16 \+ $CRIT17 \+ $CRIT18 \+ \
		$CRIT19 \+ $CRIT20 \+ $CRIT21 \+ $CRIT22 \+ $CRIT23 \+ $CRIT24 \+ \
		$CRIT25 \+ $CRIT26 \+ $CRIT27 \+ $CRIT28 \+ $CRIT29 \+ $CRIT30 \+ \
		$CRIT31 \+ $CRIT32 \+ $CRIT33 \+ $CRIT34 \+ $CRIT35 \+ $CRIT36 \+ \
		$CRIT37 \+ $CRIT38 \+ $CRIT39 \+ $CRIT40`
CTRL[7]=40
ERROR[7]="ESR PARAMETERS NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
